package mobile

import com.google.appengine.api.datastore.Entity

def rval = 'wydLogin.groovy?errorMessage=Invalid login...'

Entity user = null
def entities = datastore.execute{
	from UserE
	where id == params.userId
	limit 1
}
if(entities.size() > 0) {
	user =  entities[0]
}
boolean flag = user != null && user.password == params.password
if (flag) {
	session.user = user
	
	if(user.timeZone == null) {
		user.timeZone = 'Chennai'
	}
	def s = application.globalTimeZones[user.timeZone]
	session.userTimeZoneHour = s.substring(5, 7)
	session.userTimeZoneMinute = s.substring(8, 10)
	
	rval = 'expenses.groovy'
}

redirect rval

